package controllers;

import java.util.List;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;

import dto.Dto;
import models.User;

public class WelcomeController extends Controller{
	
	 public void index() {
//		 render("/index.jsp");
		 getUser();
	 }
	 
	 public void qr() {
		 String data  = "www.google.com";
		 renderQrCode(data, 200, 200);
	 }
	 
	 @ActionKey("/welcome/user")
	 public void getUser() {
//		 User user = new User(id,"Cat","110");
//		 this.renderJson(user);
		 List<User> users = User.dao.find("select * from user");
		 if(users==null||users.size()==0){
			 new User().set("id",null).set("password","110").set("name", "fujing").save();
			 users = User.dao.find("select * from user");
		 }
		 for(User user:users){
			 String name =  user.getName();
			 System.out.println(name);
		 }
		 Dto dto = new Dto();
		 dto.setData(users);
		 this.renderJson(Dto.getFinalDto(dto));
	 }
	 
	 public void test(){
		 User user = new User();
		 user.setName("test1");
		 user.setPassword("test");
		 user.setPhoneNumber("110");
		 user.save();
		 String id = user.getId();
		 int int_id = user.get("id");
		 renderJson(user);
	 }
}
